import Mock from 'mockjs'


// 生成随机的图片地址
function randomImageUrl() {
    const suffix = Mock.Random.guid().substring(0, 8);
    return `https://picsum.photos/200/100?random&t=${suffix}`;
  }

  // 生成分页数据
const generateData = function(currentPage, pageSize) {
    const start = (currentPage - 1) * pageSize + 1; // 起始位置
    const end = currentPage * pageSize; // 结束位置
    const data = [];
    for (let i = start; i <= end; i++) {
      data.push(Mock.mock({
        id: Mock.Random.guid(),
        url: randomImageUrl(),
        sign: true,
        missing: false,
        loading:false
      }))
    }
    return {
      total: 100,
      currentPage,
      pageSize,
      data,
    };
  };
  
  // 生成分页接口
  Mock.mock('/mock/pageList', 'post', ({body}) => {
    console.log(body)
    const {currentPage, limit} = JSON.parse(body);
    const data = generateData(currentPage, limit);
    return {
      code: 200,
      message: '',
      data,
    };
  });